home *** CD-ROM | disk | FTP | other *** search
/ FishMarket 1.0 / FishMarket v1.0.iso / fishies / 076-100 / disk_091 / adlrun / adlarith.c next >
C/C++ Source or Header  |  1992-05-06  |  859b  |  62 lines

  1. #include <stdio.h>
  2.  
  3. #include "adltypes.h"
  4. #include "adlprog.h"
  5. #include "builtins.h"
  6. #include "adlrun.h"
  7.  
  8.  
  9. int16
  10. myrand( n )
  11. int16
  12.     n;
  13. {
  14.     return 1 + ( RAND % n );
  15. }
  16.  
  17.  
  18. do_div()
  19. {
  20.     assertargs( "$div", 2 );
  21.     if( ARG(2) == 0 )
  22.     error( 1 );                /* Divide by zero */
  23.     RETVAL = ARG(1) / ARG(2);
  24. }
  25.  
  26.  
  27. do_mod()
  28. {
  29.     assertargs( "$mod", 2 );
  30.     if( ARG(2) == 0 )
  31.     error( 1 );                /* Divide by zero */
  32.     RETVAL = ARG(1) % ARG(2);
  33. }
  34.  
  35.  
  36. do_and()
  37. {
  38.     int16
  39.     i,        /* Loop counter */
  40.     tval;        /* Temporary save area */
  41.  
  42.     tval = -1;        /* Bit pattern of all ones */
  43.     for( i = 1; i < RETVAL; i++ )
  44.     tval &= ARG( i );
  45.     RETVAL = tval;
  46. }
  47.  
  48.  
  49. do_or()
  50. {
  51.     int16
  52.     i,        /* Loop counter */
  53.     tval;        /* Storage area */
  54.  
  55.     tval = 0;        /* Bit pattern of all zeros */
  56.     for( i = 1; i < RETVAL; i++ )
  57.     tval |= ARG( i );
  58.     RETVAL = tval;
  59. }
  60.  
  61. /*** EOF adlarith.c ***/
  62.